// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CLOUDAPPENGINE_CAEAPPCTRLCMDUTILS_H
#define CLOUDAPPENGINE_CAEAPPCTRLCMDUTILS_H
#include <string>
#include <map>

const std::string COMMAND_SEPARATOR = "&";
const std::string SUB_COMMAND_SEPARATOR = ":";

const std::string KEY_COMMAND = "command";

const std::string KEY_TICKET = "ticket";

const std::string KEY_IP = "ip";
const std::string KEY_PORT = "port";
const std::string KEY_SESSION_ID = "session_id";
const std::string KEY_BACKGROUND_TIMEOUT = "backgroundTimeout";
const std::string KEY_AVAILABLE_PLAYTIME = "available_playtime";
const std::string KEY_USER_ID = "user_id";
const std::string KEY_TOUCH_TIMEOUT = "touch_timeout";

const std::string KEY_ENCRYPTED_DATA = "encrypted_data";
const std::string KEY_AES_IV = "aes_iv";
const std::string KEY_AUTH_TS = "auth_ts";
const std::string KEY_VERIFY_DATA = "verify_data";

const std::string KEY_SDK_VERSION = "sdk_version";
const std::string KEY_PROTOCOL_VERSION = "protocol_version";

const std::string KEY_CLIENT_TYPE = "client_type";

const std::string KEY_MEDIA_CONFIG = "media_config";
const std::string KEY_FRAME_RATE = "fps";
const std::string KEY_BITRATE = "bitrate";
const std::string KEY_STREAM_WIDTH = "stream_width";
const std::string KEY_STREAM_HEIGHT = "stream_height";
const std::string KEY_PHYSICAL_WIDTH = "physical_width";
const std::string KEY_PHYSICAL_HEIGHT = "physical_height";
const std::string KEY_ENCODE_TYPE = "encode_type";
const std::string KEY_FRAME_TYPE = "frame_type";
const std::string KEY_REMOTE_SCHEDULING_ELB_IP = "remote_scheduling_elb_ip";
const std::string KEY_REMOTE_SCHEDULING_ELB_PORT = "remote_scheduling_elb_port";
const std::string KEY_REPEAT_FPS = "repeat_fps";
const std::string KEY_MUTE = "mute";
const std::string KEY_QUALITY = "quality";

const std::string KEY_MAX_DISCONNECT_DURATION = "max_disconnect_duration";

const std::string CMD_RESPONSE_RESULT = "result";
const std::string CMD_MSG_CODE = "code";
const std::string CMD_MSG = "msg";

const std::string KEY_VIRTUAL_DEVICE_TYPE = "virtual_device";
const uint32_t VIRTUAL_DEV_CAMERA = 0x100;
const uint32_t VIRTUAL_DEV_MICROPHONE = 0x101;
const uint32_t VIRTUAL_DEV_SENSOR = 0x102;

const int CMD_RESPONSE_FAILED = 0;
const int CMD_RESPONSE_SUCCESS = 1;

enum COMMAND_TYPE {
    CMD_HEARTBEAT = 0,
    CMD_START = 1,
    CMD_STOP = 2,
    CMD_RECONNECT = 3,
    CMD_PAUSE = 4,
    CMD_RESUME = 5,
    CMD_REQ_IFRAME = 6,
    CMD_SET_MEDIA_CONFIG = 7,
    CMD_MAX, // MAX commandType
};

const int CMD_HEARTBEAT_RESPONSE = 1000;
const int CMD_RESPONSE = 1001;
const int CMD_NOTIFY = 1002;

class CaeAppCtrlCmdUtils {
public:
    static std::string GenerateCommand(std::map<std::string, std::string> parameters,
                                       const std::string &separator = COMMAND_SEPARATOR);

    static std::map<std::string, std::string> ParseCommand(const char *data, uint32_t length,
                                                           const std::string &separator = COMMAND_SEPARATOR);

    static std::map<std::string, std::string> GenerateResponseParams(const uint32_t code);

    static std::map<std::string, std::string> GenerateNotifyParams(const uint32_t code);

    static std::map<std::string, std::string>
    GenerateParams(const uint32_t code, int cmdType, std::string msg);

    static std::map<std::string, std::string> GenerateResponseParams(const uint32_t code, std::string msg);
};

#endif // CLOUDAPPENGINE_CAEAPPCTRLCMDUTILS_H
